package com.tubang.logistics.controller;

import java.util.List;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.tubang.common.util.GsonQuick;
import com.tubang.common.util.ResultData;
import com.tubang.logistics.entity.AreaEntity;
import com.tubang.logistics.service.IAreaService;

/**
 * <p>
 * 省份表 前端控制器
 * </p>
 *
 * @author wsl
 * @since 2017-12-10
 */
@RestController
public class AreaController {
	
	private Logger logger = LoggerFactory.getLogger(getClass());
	
	@Resource
	private IAreaService areaService;
	
	/**
	 * 
	 * @Title getAreaListByPid 
	 * @Description TODO
	 * @param pid
	 * @param 设定文件 
	 * @return ResultData 返回类型 
	 * @throws
	 */
	@GetMapping("area")
	public ResultData getAreaListByPid(@RequestParam(required = true) String pid) {
		
		try {
			logger.info("method[getAreaListByPid]请求数据为：<== pid ： {}", pid);
			EntityWrapper<AreaEntity> wrapper = new EntityWrapper<>();
			wrapper.eq("pid", pid);
			List<AreaEntity> areaEntities = areaService.selectList(wrapper);
			logger.info("method[getAreaListByPid]响应数据为：<== {}", GsonQuick.getGson().toJson(areaEntities));
			return ResultData.result(true).setData(areaEntities);
		} catch (Exception e) {
			logger.error("method[getAreaListByPid]响应数据为：<== {};", e.getMessage());
			return ResultData.result(false).setData(e);
		}
		
	}
}
